package com.t2c.tibetantochinese.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.t2c.tibetantochinese.R;
import com.t2c.tibetantochinese.base.BaseFragment;
import com.t2c.tibetantochinese.fivehundred.FiveHundred;
import com.t2c.tibetantochinese.search.SearchFragment;
import com.t2c.tibetantochinese.search.SearchResultFragment;
import com.t2c.tibetantochinese.utils.CommonUtil;
import com.t2c.tibetantochinese.utils.SPUtil;
import com.t2c.tibetantochinese.views.TitleBar;
import com.t2c.tibetantochinese.wordstudy.TibetanStudy;

/**
 * Created by zoulu on 16/6/20.
 * homepage
 */
public class HomePage extends BaseFragment implements View.OnClickListener{

    @Override
    protected int getContentViewResId() {
        return R.layout.homepage_layout;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init(view);
    }

    private void init(View view){
        TextView tv1 = (TextView) view.findViewById(R.id.tv1);
        TextView tv2 = (TextView) view.findViewById(R.id.tv2);
        TextView tv3 = (TextView) view.findViewById(R.id.tv3);
        TextView tv4 = (TextView) view.findViewById(R.id.tv4);
        TitleBar titleBar = (TitleBar) view.findViewById(R.id.titlebar);
        if(CommonUtil.isChinese(getActivity())) {
            titleBar.setTitle(getResources().getString(R.string.homepage));
            tv1.setText(getResources().getString(R.string.fivehundred));
            tv2.setText(getResources().getString(R.string.searchtranslate));
            tv3.setText(getResources().getString(R.string.edictionary));
            tv4.setText("藏文字学习");
        }else{
            titleBar.getTitle().setTypeface(CommonUtil.getTibetanType(getActivity()));
            tv1.setTypeface(CommonUtil.getTibetanType(getActivity()));
            tv2.setTypeface(CommonUtil.getTibetanType(getActivity()));
            tv3.setTypeface(CommonUtil.getTibetanType(getActivity()));
            tv4.setTypeface(CommonUtil.getTibetanType(getActivity()));
            titleBar.setTitle(getResources().getString(R.string.thomepage));
            tv1.setText(getResources().getString(R.string.tfivehundred));
            tv2.setText(getResources().getString(R.string.tsearchtranslate));
            tv3.setText(getResources().getString(R.string.tedictionary));
            tv4.setText(getResources().getString(R.string.tstudy));
        }
        titleBar.setLeftVisiable(View.GONE);

        RelativeLayout iv1 = (RelativeLayout) view.findViewById(R.id.re1);
        RelativeLayout iv2 = (RelativeLayout) view.findViewById(R.id.re2);
        RelativeLayout iv3 = (RelativeLayout) view.findViewById(R.id.re3);
        RelativeLayout iv4 = (RelativeLayout) view.findViewById(R.id.re4);
        iv1.setOnClickListener(this);
        iv2.setOnClickListener(this);
        iv3.setOnClickListener(this);
        iv4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        HomeFragment homeFragment = CommonUtil.getHomeFragment(getActivity());
        switch (v.getId()){
            case R.id.re1:
                homeFragment.switchContent(new FiveHundred());
                break;
            case R.id.re2:
                homeFragment.switchContent(new SearchFragment());
                break;
            case R.id.re3:
                Fragment fragment = new SearchResultFragment();
                Bundle bundle = new Bundle();
                bundle.putInt("visiable",View.GONE);
                bundle.putInt("POS",-1);
                fragment.setArguments(bundle);
                homeFragment.switchContent(fragment);
                break;
            case R.id.re4:
                homeFragment.switchContent(new TibetanStudy());
                break;
            default:
                break;
        }
    }

}
